﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using H2.NET.Common;
using H2.NET.Web.Workflow.DwzCode;
using H2.NET.Business.Core;
using H2.NET.Data.Common;
using H2.NET.Web.Workflow.Services;

namespace H2.NET.Web.Management.Role
{
    public partial class Edit : BasePage
    {

        RoleService roleService = new RoleService();

        public t_mdc_Role role = new t_mdc_Role();

        protected void Page_Load(object sender, EventArgs e)
        {
            string _action = AksRequest.GetQueryString("action");

            if (string.IsNullOrEmpty(_action))
            {
                GetRoleInfo();
                return;
            }
            else
            {
                SaveRole();
            }
        }

        #region 获取实体信息=================================
        private void GetRoleInfo()
        {
            int id = AksRequest.GetQueryInt("id");
            if (id == 0)
            {
                ErrorMsg("传输参数不正确！");
                return;
            }

            this.role = roleService.GetModel(id);
        }
        #endregion

        #region 数据更新操作=================================
        private void SaveRole()
        {
            if (AksRequest.GetFormString("name") != "默认角色")
            {
                ErrorMsg("对不起，系统默认角色名称不能修改！");
                return;
            }

            roleService.Update(new t_mdc_Role()
            {
                Id = AksRequest.GetFormInt("id"),
                Name = AksRequest.GetFormString("name"),
                Remark = AksRequest.GetFormString("remark")
            });

            SuccessMsg("RoleIndex");
        }
        #endregion
    }
}